<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/jsp/include/taglib.jsp"%>
<%@ include file="/jsp/include/headlist.jsp"%>
<html>
<head>
	<title>卡片管理</title>

<META http-equiv="x-ua-compatible" content="IE=8">

	<script type="text/javascript">
		var refreshFlag = false;
		var isChronUser = '${sessionScope.USER_GROUPS.chron_user}';
		var isDeptUser = '${sessionScope.USER_GROUPS.dept_user}';
		$(document).ready(function() {
			$("#searchForm").validate();
			
			$("#btnSubmit").click(function(){
				$("#searchForm").submit();
			});				
			$("#resetBut").click(function(){
				$(".ul-form input:text").not('.readonly').val("");
				$(".ul-form select").val("");
			});	
			
			$("[name=checkAll]").click(function(){
				if($(this).attr("checked") == "checked"){
					$("[name=cardCheckbox]").attr("checked",true);
				}else{
					$("[name=cardCheckbox]").attr("checked",false);
				}
		    });   			
			
			window.onfocus = function(){
				if(refreshFlag){
					refreshFlag = false;
					$("#searchForm").submit();
				}
		  	};
		  	
			$('#export').click(function(){
		  		var ids="";
		  		var selectedCards = $('[name=cardCheckbox]:checked'); 
	 			if(selectedCards.length == 0){
	 				parent.$.jBox.tip('请勾选要导出的卡片','warning');
	 				return;
				}
	 			selectedCards.each(function(){
	 				//判断导出长编是否有未审核的
	  				if($(this).attr('status')=='finish')
	  					ids+=$(this).val()+",";
	  				else{
	  					//top.$.jBox.tip('只能导出已审核卡片，请重新选择.','warning');
	  					alert('当前选择卡片中存在未审核卡片，请重新选择.')
	  					$('[name=cardCheckbox]').attr('checked',false);
	  					$("[name=checkAll]").attr('checked',false);
						ids='';
	  					return false;
	  				}
	 			});
		  		if(ids!=''){
		  			ids=ids.substr(0,ids.length-1);
		  			parent.$.jBox.tip('努力下载中,请耐心等待...','warning');
		  			$(this).attr('href', "${ctx}/card/exportCards/"+ids+"?ticket=1_1&lv=4&objFilter=nobj,catalog&resourceType=${param.resourceType}");
		  		}
		  	});
			
			
			$('#exportAll').click(function(){

				if(!confirm("是否导出卡片全文,请确认?"))
					return;
				
				
				var nodes=parent.zTreeobj.getNodes();

				var ids='';
				$.each(nodes,function(i,n){
					ids+=n.nid+",";
				});
				ids=ids.substring(0,ids.length-1);
				$.jBox.tip('努力下载中,请耐心等待...','warning');
				$(this).attr({'href':"${ctx}/card/exportAll?ids="+ids+"&ticket=1_1&lv=4&objFilter=nobj,catalog&resourceType=${param.resourceType}","target":"_blank"});
			});

		});

		function createSummary(){
			var selectedCards = $('[name=cardCheckbox]:checked'); 
 			if(selectedCards.length == 0){
 				parent.$.jBox.tip('请勾选要长编的卡片','warning');
 				return;
			}
 			var tips = '';
 			selectedCards.each(function(){
 				if($(this).attr('summaryId') || $(this).attr('status') != 'finish'){
 					tips += '只能选择已审核且还未长编的卡片！';
 					return false;
 				}
 			});
 			if(tips){
 				parent.$.jBox.tip(tips,'warning');
 				return; 				
 			}
			$("#gridForm").submit();
		}
		
	  
		function forceRefresh(){
			refreshFlag = true;
		}
		
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function beforeAdd(){
			if(parent.selectedCatalog){
				forceRefresh();
				return true;
			}else{
				parent.$.jBox.tip('没有选择目录！','warning');
				return false;
			}
		}
		
		function showTransfer(){
			if($('[name=cardCheckbox]:checked').length == 0){
				parent.$.jBox.tip('请勾选需要移动的卡片','warning');
				return;
			}
			$.jBox.open("iframe:${ctx}/jsp/catalog/catalogList.jsp?type=card&resourceType=${param.resourceType}&op=0", "选择迁移目录",220,400,{
				buttons:{"确定":true}, loaded:function(h){
					$(".jbox-content", document).css("overflow-y","hidden");
				},
				submit: function(h){
					if(!selectedCatalog){
						parent.$.jBox.tip('请选择目录!','warning');
						return false;
					}
					
					var nIds = '';
					$('[name=cardCheckbox]:checked').each(function(){
						nIds += ','+$(this).val();
					})
					if(nIds.length > 0){
						nIds = nIds.substr(1);
					}
					
					$.ajax({
						url : "${ctx}/card/rebindCatalog?r="+Math.random(),
						type : 'post',
						data: {
					        pIdNew : selectedCatalog.nid,
					        cardIds : nIds,
					        code : selectedCatalog.parentCode
						},
						success: function(data, status, xhr) {
				            if(data == '1'){
				            	alert('操作成功！');
				            	$("#searchForm").submit();
				            }else{
				            	alert("对不起！你的请求出现异常，请联系服务人员！");
				            }
						},
						error:function(XMLHttpRequest, textStatus, errorThrown){
					    	alert("对不起！你的请求出现异常，请联系服务人员！");
						}
					});		
		 			/* $.ajax({
					    url : "${ctx}/catalog/getCode/" + selectedCatalog.nid + "?ticket=1_1&objFilter=nobj,catalog&r="+Math.random(),
						type : 'get',
						dataType:'json',
						success:function(result){
							if(result.info.success){
								$.ajax({
									url : "${ctx}/card/rebindCatalog?r="+Math.random(),
									type : 'post',
									data: {
								        pIdNew : selectedCatalog.nid,
								        cardIds : nIds,
								        code : result.data
									},
									success: function(data, status, xhr) {
							            if(data == '1'){
							            	alert('操作成功！');
							            	$("#searchForm").submit();
							            }else{
							            	alert("对不起！你的请求出现异常，请联系服务人员！");
							            }
									},
									error:function(XMLHttpRequest, textStatus, errorThrown){
								    	alert("对不起！你的请求出现异常，请联系服务人员！");
									}
								});								
							}
						},
						error:function(XMLHttpRequest, textStatus, errorThrown){
					    	alert("对不起！你的请求出现异常，请联系服务人员！");
						}
					});	 */				
				}
			});
		}
		
		var selectedCatalog = null;
		function onCatalogSelected(treeNode){
			selectedCatalog = treeNode;
		}		
		
		function doDel(id){
			parent.$.jBox.confirm("确定要删除吗？", "删除确认", function(v, h, f){
				if(v == 'ok'){
					$.ajax({
					    url : "${ctx}/card/del/"+id,
						type : 'delete',
						success: function(data, status, xhr) {
							alert("删除成功！");
							$("#searchForm").submit();
				        }, 
				        error: function() {
				        	alert("对不起！你的请求出现异常，请联系服务人员！");
						}
					});						
				}
				return true;
			});
		}
		
		
		
	</script>
	<style>
	.form-search .ul-form li label {
		width: 110px;
	}
	.table th, .table td {text-align:center}
	.t_l{text-align:left}
	</style>
</head>
<body>
	<form id="searchForm" action="${ctx}/card/list" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.currentPage}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input name="pId" type="hidden" value="${params.pId}"/>
		<input name="pType" type="hidden" value="${params.pType}"/>
		<input name="pCode" type="hidden" value="${params.pCode}"/>
		<input name="lv" type="hidden" value="${params.lv}"/>
		<input name="id_in" type="hidden" value="${params.id_in}"/>
		<input type="hidden" name="summaryId" value="${params.summaryId}" />
		<input type="hidden" name="op" value="${params.op}" />
		<input type="hidden" name="resourceType" value="${params.resourceType}" />
		<ul class="ul-form">
			<li><label>资料代码：</label>
			<input type="text" name="code_l" maxlength="50" class="input-small" value="${params.code_l}"/>
			</li>
			<li><label>关键词：</label>
			<input type="text" name="keyword_l" maxlength="50" class="input-small" value="${params.keyword_l}"/>
			</li>		
			<li><label>资料内容标题：</label>
			<input type="text" name="contentTitle_l" maxlength="50" class="input-small" value="${params.contentTitle_l}"/>
			</li>			
			<li><label>资料来源：</label>
			<input type="text" name="source_l" maxlength="50" class="input-small" value="${params.source_l}"/>
			</li>
			<li><label>资料正文：</label>
			<input type="text" name="content_l" maxlength="50" class="input-small" value="${params.content_l}"/>
			</li>
			<li><label>资料整理者：</label>
			<input type="text" name="operateUser_l" maxlength="50" class="input-small" value="${params.operateUser_l}"/>
			</li>			
			<li><label>资料内容时间：</label>
			<input type="text" class="input-small" name="contentTimeEnd_s" value="${params.contentTimeEnd_s}" readonly onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			~<input type="text" class="input-small" name="contentTimeStart_e" value="${params.contentTimeStart_e}" readonly onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			</li>		
			<li><label>资料整理时间：</label>
			<input type="text" class="input-small" name="operateTime_s" value="${params.operateTime_s}" readonly onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			~<input type="text" class="input-small" name="operateTime_e" value="${params.operateTime_e}" readonly onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			</li>					
			<li><label>资料报送单位：</label>
			<input type="text" name="operateDept_l" maxlength="50" class="input-small" value="${params.operateDept_l}"/>
			</li>									
			<li><label>审核状态：</label>
		      <select name="status" class="input-medium-select creset">
		        <c:forEach items="${fields.status.option}" var="op">
		          <option value="${op.key}" ${op.key==params.status ? 'selected':''}>${op.value}</option>
		        </c:forEach>
		      </select>			
			</li>						
			<li class="clearfix"></li>
		</ul>
		<div class="input01"><a id="btnSubmit" href="javascript:void(0)">查询</a><a id="resetBut" href="javascript:void(0)">重置</a></div>		
	</form>
	<c:if test="${params.op!='0'}">
	<div class="wd-butbar">
	     <div class="top-a">
	      <a class="a01" href="javascript:createSummary()" onclick="forceRefresh()">长编汇总</a>
	      <a class="a04" href="${ctx}/card/add?pId=${params.pId}&pType=${params.pType}&pCode=${params.pCode}" target="_blank" onclick="return beforeAdd()" title="新增卡片"></a>
	      <!-- <a class="a05"></a> href="${ctx}/card/exportCards/92,93,86,80,70?ticket=1_1&lv=4&objFilter=nobj,catalog&resourceType=${param.resourceType}"-->
	      <a class="a05" id='export'  title="卡片导出" ></a>
	      <a class="a06" href="javascript:showTransfer();" title="移动卡片"></a>
<!-- 	      <a class="a07"></a> -->
	      <a class="a08" id='exportAll'  title="全文导出"></a> 
<!-- 	      <a class="a09"></a>  -->
	     </div>	
	</div>	
	</c:if>
	<form id="gridForm" action="${ctx}/summary/create" method="post" target="_blank">
	<input type="hidden" name="resourceType" value="${params.resourceType}" />
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr><th width="30px"><c:if test="${params.op!='0'}"><input name="checkAll" type="checkbox" value=""></c:if>序号</th>
				<th width="10%">资料代码</th>
				<th width="10%">卡片序号</th>
				<th>资料内容开始时间</th>
				<th>资料内容结束时间</th>
				<th>资料内容标题</th>
				<th>报送单位</th>
				<th>资料整理者</th>
				<th>资料整理时间</th>
				<th>审核状态</th>
				<th>长编</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${list}" var="card"  varStatus="rownum" >
			<tr>
				<td style="text-align: center;">
					<c:if test="${(sessionScope.isChron || sessionScope.deptId==card.operateDeptId) && params.op!='0'}">
						<input name="cardCheckbox" type="checkbox" value="${card.id}" summaryId="${card.summaryId}" status="${card.status}">
					</c:if>
					${rownum.count}
				</td>
				<td class="t_l">
					${card.code}
				</td>
				<td>
					${card.cardNo}
				</td>
				<td>
					${card.contentTimeStart}
				</td>
				<td>
					${card.contentTimeEnd}
				</td>
				<td>
					${card.contentTitle}
				</td>
				<td>
					${card.operateDept}
				</td>				
				<td>
					${card.operateUser}
				</td>				
				<td>
					${card.operateTime}
				</td>								
				<td>
					${fields.status.option[card.status]}
				</td>	
				<td>
					<c:if test="${card.summaryId==null}">
						否
					</c:if>
					<c:if test="${card.summaryId!=null}">
						是
					</c:if>					
				</td>					
				<td>
					<a href="${ctx}/card/view?id=${card.id}" target="_blank">查看</a>
					<%-- <c:if test="${((card.status == 'draft' && (sessionScope.isChron || sessionScope.deptId==card.operateDeptId)) || ((card.status == 'modify' || card.status == 'cancle') && sessionScope.userId == card.operateUserId)) --%>
					<c:if test="${((card.status == 'draft' || card.status == 'modify' || card.status == 'cancle') && sessionScope.userId == card.operateUserId) 
									&& params.op!='0'}">
						<a href="${ctx}/card/edit?id=${card.id}" target="_blank" onclick="forceRefresh()">修改</a>
					</c:if>
					<c:if test="${(card.status == 'draft') && (sessionScope.isChron || sessionScope.deptId==card.operateDeptId) && params.op!='0'}">
						<a href="javascript:doDel('${card.id}');">删除</a>
					</c:if>
				</td>						
			</tr>
		</c:forEach>
		</tbody>
	</table>
	</form>
	<div class="pagination">${pagination}</div>
</body>
</html>